package com.example.servicedemo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService1 extends Service {

    private static final String TAG = "MyService1";

    public MyService1() {
    }

    // 服务创建
    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate");
    }

    // 服务开始
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    // 服务销毁
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");
    }

    // 绑定
    @Override
    public IBinder onBind(Intent intent) {
        return new MyBind();
    }

    // 解绑
    @Override
    public boolean onUnbind(Intent intent) {
        return super.onUnbind(intent);
    }

    public class MyBind extends Binder {
        public MyService1 getService() {
            return MyService1.this;
        }
    }

    public void xxx() {
        Toast.makeText(this, "service方法被调用", Toast.LENGTH_LONG).show();
    }

}